#include "StdAfx.h"
#include "IEchoServer.h"

// Includes for factory method.
#include "EchoServerAO.h"

namespace CO { namespace SpiFoundation { namespace RoomFW {

//
// TODO: Implement factory method to create derived type objects.
//
IEchoServerSP IEchoServer::Create(const char* objectName)
{
	IEchoServerSP retVal;
	retVal.reset(new EchoServerAO(objectName));
	return retVal;
}

//
// TODO:  Add priority for each port in order declared, including timer.
//
const SpiFoundation::RoomFW::ActiveObject::PortPriority IEchoServer::PortPriorities[] = {
	PRI_NORMAL,
	PRI_NORMAL,
	PRI_HIGH	// PORT_TIMER
};
const size_t IEchoServer::PortPrioritiesSize = sizeof(IEchoServer::PortPriorities) / sizeof(IActiveObject::PortPriority);
BOOST_STATIC_ASSERT(IEchoServer::PortPrioritiesSize == IEchoServer::PORT_COUNT + 1);

IEchoServer::IEchoServer(void) :
	//
	// TODO:  Initialize protocol attributes.
	//
	inProtocol_(false),	// false = not conjugated.
	outProtocol_(true)	// true = conjugated.
{
}

IEchoServer::~IEchoServer(void)
{
}

const char* IEchoServer::getPortName(size_t portIndex) const
{
	//
	// TODO:  Add text for each port name for debugging.
	//
	const char* retVal = "UNKNOWN_PORT";
	switch (portIndex)
	{
	case PORT_ECHO_IN:
		retVal = "PORT_ECHO_IN";
		break;
	case PORT_ECHO_OUT:
		retVal = "PORT_ECHO_OUT";
		break;
	case PORT_TIMER:
		retVal = "PORT_TIMER";
		break;
	//default:
	//	ASSERT(false); // Invalid port.
	};
	return retVal;
}

SpiFoundation::RoomFW::IContractCheckerSPC
IEchoServer::getContractChecker(SpiFoundation::RoomFW::PortIndex portIndex) const
{
	//
	// TODO:  Return the contract checker for each port.
	//
	SpiFoundation::RoomFW::IContractCheckerSPC retVal;
	switch (portIndex.port())
	{
	case PORT_ECHO_IN:
		retVal = SpiFoundation::RoomFW::IContractCheckerSPC(&inProtocol_, GenericTestProtocolNullDeleter());
		break;
	case PORT_ECHO_OUT:
		retVal = SpiFoundation::RoomFW::IContractCheckerSPC(&outProtocol_, GenericTestProtocolNullDeleter());
		break;
	//default:
	//	ASSERT(false); // Invalid port.
	}
	return retVal;
}

}}}